<template>
  <div class="song-detail">
    <!-- 头部区域 -->
    <div :class="['header', { 'compact': isHeaderCompact }]">
      <div class="back-btn" @click="goBack">
        <el-icon><ArrowLeft /></el-icon>
      </div>
      <div class="song-info">
        <div class="song-title-container">
          <h1 class="song-title">{{ songInfo.title }}</h1>
          <p class="artist-name">{{ songInfo.artist }}</p>
        </div>
      </div>
      <!-- 设置按钮 -->
      <div class="settings-btn" @click="toggleSettings">
        <el-icon><Setting /></el-icon>
      </div>
    </div>

    <!-- 设置面板 -->
    <div class="settings-panel" v-if="showSettings" @click.stop>
      <div class="settings-header">
        <span>设置</span>
        <div class="close-settings" @click="showSettings = false">
          <el-icon><Close /></el-icon>
        </div>
      </div>
      <div class="settings-content">
        <div class="setting-item">
          <span class="setting-label">显示拼音</span>
          <div :class="['setting-switch', { active: showPinyin }]" @click="togglePinyin">
            <div class="setting-switch-slider"></div>
          </div>
        </div>
        <div class="setting-item">
          <span class="setting-label">显示谐音</span>
          <div :class="['setting-switch', { active: showPhonetic }]" @click="togglePhonetic">
            <div class="setting-switch-slider"></div>
          </div>
        </div>
      </div>
    </div>

    <!-- 点击其他区域关闭设置面板 -->
    <div class="settings-overlay" v-if="showSettings" @click="showSettings = false"></div>

    <!-- 歌词内容区域 -->
    <div class="lyrics-container">
      <div class="lyrics-content">
        <div 
          v-for="(section, index) in lyrics" 
          :key="index" 
          :class="['lyrics-section', { 'selected': selectedSection === index }]"
          @click="selectSection(index)"
        >
          <div class="section-label">第{{ ['一', '二', '三', '四', '五'][index] }}段</div>
          <!-- 播放标志动画，只在选中状态显示 -->
          <div v-if="selectedSection === index" class="playing-indicator">
            <div class="bar bar1"></div>
            <div class="bar bar2"></div>
            <div class="bar bar3"></div>
          </div>
          <div 
            v-for="(line, lineIndex) in section.lines" 
            :key="lineIndex" 
            class="lyrics-line"
          >
            <!-- 原始歌词行 -->
            <div class="lyrics-char-grid">
              <template v-for="(char, charIndex) in line.chars" :key="charIndex">
                <div class="char-column">
                  <div v-if="showPinyin" class="pinyin-char">{{ char.pinyin || '&nbsp;' }}</div>
                  <div class="chinese-char">{{ char.chinese }}</div>
                  <div v-if="showPhonetic" class="phonetic-char">{{ char.phonetic || '&nbsp;' }}</div>
                </div>
              </template>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 统一的底部控制背景 -->
    <div :class="['bottom-controls-bg', { 'collapsed': isKeyboardCollapsed }]">
      <!-- 播放控制区域 -->
      <div class="player-controls">
        <!-- 循环开关独立定位 -->
        <div class="loop-control">
          <div :class="['loop-switch', { active: isLooping }]" @click="toggleLoop">
            <div class="loop-switch-slider"></div>
          </div>
          <div class="loop-label">循环</div>
        </div>
        
        <!-- 主要播放控制按钮保持居中 -->
        <div class="main-control-buttons">
          <div class="control-btn" @click="previousSong">
            <img src="../assets/pre.svg" alt="上一曲" class="control-icon">
          </div>
          <div class="play-btn" @click="togglePlay">
            <img v-if="!isPlaying" src="../assets/play.svg" alt="播放" class="play-icon">
            <img v-else src="../assets/zanting.svg" alt="暂停" class="play-icon">
          </div>
          <div class="control-btn" @click="nextSong">
            <img src="../assets/next.svg" alt="下一曲" class="control-icon">
          </div>
        </div>

        <!-- 收起按钮 -->
        <div class="collapse-btn" @click="toggleKeyboard">
          <el-icon :class="{ 'rotate-180': isKeyboardCollapsed }">
            <ArrowDown />
          </el-icon>
        </div>
      </div>

      <!-- 学习模式区域 -->
      <div class="learning-modes">
        <div class="mode-buttons">
          <button 
            :class="['mode-btn', learningMode === 'study' ? 'primary' : 'secondary']"
            @click="setLearningMode('study')"
          >
            学歌模式
          </button>
          <button 
            :class="['mode-btn', learningMode === 'practice' ? 'primary' : 'secondary']"
            @click="setLearningMode('practice')"
          >
            粤语练习
          </button>
        </div>
      </div>

      <!-- 底部练习选项 - 可收起 -->
      <div class="practice-options" :class="{ 'hidden': isKeyboardCollapsed }">
        <!-- 粤语练习模式的选项 -->
        <div v-if="learningMode === 'practice'" class="option-tabs practice-grid">
          <div 
            v-for="option in practiceOptions" 
            :key="option.id"
            :class="['option-tab', { active: activePractice === option.id }]"
            @click="activePractice = option.id"
          >
            {{ option.name }}
          </div>
        </div>
        
        <!-- 学歌模式的选项 -->
        <div v-else class="option-tabs study-grid">
          <div 
            v-for="option in studyOptions" 
            :key="option.id"
            :class="['option-tab', { active: activePractice === option.id }]"
            @click="activePractice = option.id"
          >
            {{ option.name }}
          </div>
        </div>
      </div>
    </div>

    <!-- 使用教程按钮 -->
    <div class="tutorial-btn" @click="showTutorial">
      <span class="tutorial-text">使用教程</span>
    </div>

    <!-- 教程弹窗 -->
    <div class="tutorial-overlay" v-if="showTutorialModal" @click="closeTutorial"></div>
    <div class="tutorial-modal" v-if="showTutorialModal">
      <div class="tutorial-header">
        <h3>使用教程</h3>
        <div class="close-tutorial" @click="closeTutorial">
          <el-icon><Close /></el-icon>
        </div>
      </div>
      <div class="tutorial-content">
        <div class="tutorial-step">
          <div class="step-number">1</div>
          <div class="step-text">点击"学歌模式"或"粤语练习"选择学习方式</div>
        </div>
        <div class="tutorial-step">
          <div class="step-number">2</div>
          <div class="step-text">在歌词中点击想要学习的段落</div>
        </div>
        <div class="tutorial-step">
          <div class="step-number">3</div>
          <div class="step-text">可在设置中开关拼音和谐音显示</div>
        </div>
        <div class="tutorial-step">
          <div class="step-number">4</div>
          <div class="step-text">使用底部键盘选择不同练习模式</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import { ArrowLeft, ArrowDown, Setting, Close, QuestionFilled } from '@element-plus/icons-vue'

const props = defineProps({
  songData: {
    type: Object,
    default: () => ({})
  }
})

const emit = defineEmits(['back'])

const isPlaying = ref(false)
const activePractice = ref(1)
const isLooping = ref(false)
const learningMode = ref('practice') // 默认选中粤语练习
const isHeaderCompact = ref(false) // 标题栏是否紧凑模式
const isKeyboardCollapsed = ref(false) // 键盘是否收起
const selectedSection = ref(null) // 当前选中的段落

const songInfo = ref({
  title: '姐姐所爱的歌',
  artist: '小艺'
})

const lyrics = ref([
  {
    lines: [
      { 
        chars: [
          { pinyin: 'zhè', chinese: '这', phonetic: 'zhe2' },
          { pinyin: 'shì', chinese: '是', phonetic: 'si6' },
          { pinyin: 'yī', chinese: '一', phonetic: 'yat1' },
          { pinyin: 'shǒu', chinese: '首', phonetic: 'sau2' },
          { pinyin: 'gē', chinese: '歌', phonetic: 'go1' }
        ] 
      },
      { 
        chars: [
          { pinyin: 'wǒ', chinese: '我', phonetic: 'ngo5' },
          { pinyin: 'ài', chinese: '爱', phonetic: 'oi3' },
          { pinyin: 'chàng', chinese: '唱', phonetic: 'cheong3' },
          { pinyin: 'gē', chinese: '歌', phonetic: 'go1' }
        ] 
      }
    ]
  },
  {
    lines: [
      { 
        chars: [
          { pinyin: 'měi', chinese: '每', phonetic: 'mui5' },
          { pinyin: 'tiān', chinese: '天', phonetic: 'tin1' },
          { pinyin: 'dōu', chinese: '都', phonetic: 'dou1' },
          { pinyin: 'hěn', chinese: '很', phonetic: 'han2' },
          { pinyin: 'kuài', chinese: '快', phonetic: 'faai3' },
          { pinyin: 'lè', chinese: '乐', phonetic: 'lok6' }
        ] 
      },
      { 
        chars: [
          { pinyin: 'yīn', chinese: '音', phonetic: 'yam1' },
          { pinyin: 'yuè', chinese: '乐', phonetic: 'ngok6' },
          { pinyin: 'hěn', chinese: '很', phonetic: 'han2' },
          { pinyin: 'měi', chinese: '美', phonetic: 'mei5' },
          { pinyin: 'hǎo', chinese: '好', phonetic: 'hou2' }
        ] 
      }
    ]
  },
  {
    lines: [
      { 
        chars: [
          { pinyin: 'jiě', chinese: '姐', phonetic: 'ze2' },
          { pinyin: 'jiě', chinese: '姐', phonetic: 'ze2' },
          { pinyin: 'suǒ', chinese: '所', phonetic: 'so2' },
          { pinyin: 'ài', chinese: '爱', phonetic: 'oi3' },
          { pinyin: 'de', chinese: '的', phonetic: 'di1' },
          { pinyin: 'gē', chinese: '歌', phonetic: 'go1' }
        ] 
      },
      { 
        chars: [
          { pinyin: 'ràng', chinese: '让', phonetic: 'yeung6' },
          { pinyin: 'wǒ', chinese: '我', phonetic: 'ngo5' },
          { pinyin: 'lái', chinese: '来', phonetic: 'loi4' },
          { pinyin: 'chàng', chinese: '唱', phonetic: 'cheong3' },
          { pinyin: 'gē', chinese: '歌', phonetic: 'go1' }
        ] 
      },
      { 
        chars: [
          { pinyin: 'yǒu', chinese: '有', phonetic: 'yau5' },
          { pinyin: 'shí', chinese: '时', phonetic: 'si4' },
          { pinyin: 'huì', chinese: '会', phonetic: 'wui5' },
          { pinyin: 'kěn', chinese: '肯', phonetic: 'hang2' },
          { pinyin: 'néng', chinese: '能', phonetic: 'nang4' }
        ] 
      },
      { 
        chars: [
          { pinyin: 'chàng', chinese: '唱', phonetic: 'cheong3' },
          { pinyin: 'nà', chinese: '那', phonetic: 'na5' },
          { pinyin: 'shǒu', chinese: '首', phonetic: 'sau2' },
          { pinyin: 'gē', chinese: '歌', phonetic: 'go1' }
        ] 
      }
    ]
  }
])

const practiceOptions = ref([
  { id: 1, name: '单字练习' },
  { id: 2, name: '单句练习' },
  { id: 3, name: '整段带读' },
  { id: 4, name: '整段连读' },
  { id: 5, name: '全曲带读' },
  { id: 6, name: '全曲连读' }
])

const studyOptions = ref([
  { id: 1, name: '单句练习' },
  { id: 2, name: '整段带唱' },
  { id: 3, name: '整段连唱' },
  { id: 4, name: '整段伴奏' },
  { id: 5, name: '全曲带唱' },
  { id: 6, name: '全曲连唱' },
  { id: 7, name: '全曲伴奏' }
])

const showSettings = ref(false)
const showPinyin = ref(true)
const showPhonetic = ref(false)

const showTutorialModal = ref(false)

const goBack = () => {
  emit('back')
}

const togglePlay = () => {
  isPlaying.value = !isPlaying.value
}

const previousSong = () => {
  console.log('Previous song')
}

const nextSong = () => {
  console.log('Next song')
}

const toggleLoop = () => {
  isLooping.value = !isLooping.value
}

const toggleKeyboard = () => {
  isKeyboardCollapsed.value = !isKeyboardCollapsed.value
  updateLyricsContainerPadding()
}

const updateLyricsContainerPadding = () => {
  const lyricsContainer = document.querySelector('.lyrics-container')
  if (lyricsContainer) {
    lyricsContainer.style.paddingBottom = isKeyboardCollapsed.value ? '140px' : '260px'
  }
}

const setLearningMode = (mode) => {
  learningMode.value = mode
  activePractice.value = 1 // 切换模式时重置为第一个选项
  
  // 如果键盘是收起状态，则展开它
  if (isKeyboardCollapsed.value) {
    isKeyboardCollapsed.value = false
    updateLyricsContainerPadding()
  }
}

const selectSection = (index) => {
  if (selectedSection.value === index) {
    selectedSection.value = null // 再次点击取消选择
  } else {
    selectedSection.value = index // 选择段落
  }
}

// 滚动处理
const handleScroll = () => {
  const scrollTop = document.querySelector('.lyrics-container')?.scrollTop || 0
  isHeaderCompact.value = scrollTop > 20
}

const toggleSettings = (event) => {
  event.stopPropagation()
  showSettings.value = !showSettings.value
}

const togglePinyin = () => {
  showPinyin.value = !showPinyin.value
}

const togglePhonetic = () => {
  showPhonetic.value = !showPhonetic.value
}

// 关闭设置面板的点击事件处理
const handleDocumentClick = (event) => {
  if (showSettings.value) {
    const settingsPanel = document.querySelector('.settings-panel')
    const settingsBtn = document.querySelector('.settings-btn')
    if (settingsPanel && !settingsPanel.contains(event.target) && 
        settingsBtn && !settingsBtn.contains(event.target)) {
      showSettings.value = false
    }
  }
}

// 显示教程弹窗
const showTutorial = () => {
  showTutorialModal.value = true
}

// 关闭教程弹窗
const closeTutorial = () => {
  showTutorialModal.value = false
}

// 生命周期钩子
onMounted(() => {
  const lyricsContainer = document.querySelector('.lyrics-container')
  if (lyricsContainer) {
    lyricsContainer.addEventListener('scroll', handleScroll)
    updateLyricsContainerPadding()
  }
  
  // 添加全局点击事件监听器
  document.addEventListener('click', handleDocumentClick)
})

onUnmounted(() => {
  const lyricsContainer = document.querySelector('.lyrics-container')
  if (lyricsContainer) {
    lyricsContainer.removeEventListener('scroll', handleScroll)
  }
  
  // 移除全局点击事件监听器
  document.removeEventListener('click', handleDocumentClick)
})
</script>

<style scoped>
.song-detail {
  height: 100vh;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  background: linear-gradient(135deg, #3d3878 0%, #1a1732 100%);
  color: white;
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  overflow: hidden;
  position: relative;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
}

/* 头部区域 */
.header {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(61, 56, 120, 0.9);
  backdrop-filter: blur(10px);
  z-index: 100;
  flex-shrink: 0;
  min-height: 44px;
  transition: all 0.3s ease;
  position: sticky;
  top: 0;
}

.header.compact {
  min-height: 44px;
}

.back-btn {
  font-size: 20px;
  color: white;
  cursor: pointer;
  margin-right: 16px;
  padding: 12px;
  border-radius: 50%;
  transition: background-color 0.2s ease;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.back-btn:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.song-info {
  flex: 1;
  min-width: 0;
  transition: all 0.3s ease;
}

.song-title-container {
  transition: all 0.3s ease;
}

.header.compact .song-title-container {
  display: flex;
  align-items: center;
}

.song-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 4px 0;
  color: white;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.3s ease;
}

.header.compact .song-title {
  font-size: 16px;
  margin: 0;
}

.artist-name {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.7);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.3s ease;
}

.header.compact .artist-name {
  font-size: 12px;
  margin: 0 0 0 8px;
}

/* 歌词内容区域 */
.lyrics-container {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px;
  padding-bottom: 260px;
  -webkit-overflow-scrolling: touch;
  transition: padding-bottom 0.3s ease;
}

.lyrics-content {
  padding-top: 20px;
}

.lyrics-section {
  margin-bottom: 12px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 10px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.3s ease;
  cursor: pointer;
  position: relative;
}

.lyrics-section.selected {
  background: rgba(139, 92, 246, 0.15);
  border: 1px solid rgba(139, 92, 246, 0.4);
  box-shadow: 0 0 15px rgba(139, 92, 246, 0.3);
  transform: translateY(-2px);
}

.section-label {
  background: linear-gradient(135deg, #8B5CF6 0%, #5B21B6 100%);
  color: white;
  padding: 4px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  display: inline-block;
  margin-bottom: 8px;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}

.lyrics-line {
  margin-bottom: 8px;
  line-height: 1.3;
}

.lyrics-line:last-child {
  margin-bottom: 0;
}

.lyrics-char-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  padding: 2px 0;
}

.char-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-right: 4px;
  min-width: 20px;
}

.pinyin-char {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 1px;
  font-style: italic;
  line-height: 1.1;
  text-align: center;
  height: 12px;
}

.chinese-char {
  font-size: 16px;
  color: white;
  font-weight: 500;
  line-height: 1.2;
  text-align: center;
  height: 20px;
  margin-bottom: 1px;
}

.phonetic-char {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
  font-style: italic;
  line-height: 1.1;
  text-align: center;
  height: 12px;
}

/* 统一的底部控制背景 */
.bottom-controls-bg {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 260px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  z-index: 98;
  padding: 0 20px;
  transition: height 0.3s ease;
}

.bottom-controls-bg.collapsed {
  height: 140px;
}

/* 播放控制区域 */
.player-controls {
  padding: 16px 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  position: absolute;
  top: -15px;
  left: 0;
  right: 0;
  background: transparent;
  z-index: 99;
}

/* 循环控制区域 */
.loop-control {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

/* 循环开关样式 */
.loop-switch {
  width: 40px;
  height: 20px;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  position: relative;
}

.loop-switch:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

.loop-switch.active {
  background: linear-gradient(135deg, #8B5CF6 0%, #5B21B6 100%);
  border-color: rgba(139, 92, 246, 0.5);
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.3);
}

.loop-switch-slider {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 2px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: all 0.3s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.loop-switch.active .loop-switch-slider {
  left: calc(100% - 18px);
}

/* 循环文字标签 */
.loop-label {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.7);
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  margin-top: 4px;
}

/* 主要控制按钮居中 */
.main-control-buttons {
  display: flex;
  align-items: center;
  gap: 7px;
  justify-content: center;
}

.control-btn {
  font-size: 24px;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 12px;
  border-radius: 50%;
  min-width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
}

.control-btn:hover {
  color: white;
  background-color: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

.control-icon {
  width: 24px;
  height: 24px;
  transition: all 0.3s ease;
}

.control-btn:hover .control-icon {
  transform: scale(1.1);
}

.play-btn {
  cursor: pointer;
  background: transparent;
  border: none;
  border-radius: 0;
  width: auto;
  height: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  padding: 12px;
}

.play-icon {
  width: 56px;
  height: 56px;
  transition: all 0.3s ease;
}

.play-btn:hover .play-icon {
  transform: scale(1.1);
}

/* 学习模式区域 */
.learning-modes {
  padding: 12px 20px;
  flex-shrink: 0;
  position: absolute;
  top: 70px;
  left: 0;
  right: 0;
  background: transparent;
  z-index: 100;
}

.mode-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.mode-btn {
  padding: 8px 20px;
  border-radius: 20px;
  border: none;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 90px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mode-btn.primary {
  background: linear-gradient(135deg, #8B5CF6 0%, #5B21B6 100%);
  color: white;
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.3);
}

.mode-btn.secondary {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.mode-btn:hover {
  transform: translateY(-2px);
}

/* 底部练习选项 */
.practice-options {
  position: absolute;
  bottom: 20px;
  left: 0;
  right: 0;
  background: transparent;
  padding: 16px 20px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 100;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.practice-options.hidden {
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
}

.option-tabs {
  display: grid;
  gap: 8px;
}

/* 粤语练习模式：3列2行 */
.practice-grid {
  grid-template-columns: repeat(3, 1fr);
}

/* 学歌模式：上4下3布局 */
.study-grid {
  grid-template-columns: repeat(12, 1fr);
  grid-template-rows: auto auto;
}

/* 上方四个按钮，每个占3列 */
.study-grid .option-tab:nth-child(1) { grid-column: 1 / 4; }
.study-grid .option-tab:nth-child(2) { grid-column: 4 / 7; }
.study-grid .option-tab:nth-child(3) { grid-column: 7 / 10; }
.study-grid .option-tab:nth-child(4) { grid-column: 10 / 13; }

/* 下方三个按钮，每个占4列 */
.study-grid .option-tab:nth-child(5) { grid-column: 1 / 5; }
.study-grid .option-tab:nth-child(6) { grid-column: 5 / 9; }
.study-grid .option-tab:nth-child(7) { grid-column: 9 / 13; }

.option-tab {
  padding: 10px 6px;
  text-align: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid rgba(255, 255, 255, 0.15);
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
}

.option-tab:hover {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  transform: translateY(-1px);
}

.option-tab.active {
  background: linear-gradient(135deg, #8B5CF6 0%, #5B21B6 100%);
  color: white;
  border-color: transparent;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.4);
}

/* 滚动条样式 */
.lyrics-container::-webkit-scrollbar {
  width: 3px;
}

.lyrics-container::-webkit-scrollbar-track {
  background: transparent;
}

.lyrics-container::-webkit-scrollbar-thumb {
  background: rgba(139, 92, 246, 0.5);
  border-radius: 3px;
}

.lyrics-container::-webkit-scrollbar-thumb:hover {
  background: rgba(139, 92, 246, 0.7);
}

/* 移动端安全区域适配 */
@supports (padding: max(0px)) {
  .practice-options {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  
  .header {
    padding-top: max(12px, env(safe-area-inset-top));
  }
}

/* 小屏适配（≤375px） */
@media (max-width: 375px) {
  .lyrics-container {
    padding: 0 16px;
    padding-bottom: 260px;
  }
  
  .lyrics-section {
    padding: 12px;
    margin-bottom: 20px;
  }
  
  .bottom-controls-bg {
    padding: 0 16px;
  }
  
  .player-controls .loop-control {
    left: 16px;
  }
}

/* 超小屏（320px）适配 */
@media (max-width: 320px) {
  .header {
    padding: 8px 16px;
  }
  
  .lyrics-container {
    padding: 0 12px;
    padding-bottom: 260px;
  }
  
  .bottom-controls-bg {
    padding: 0 12px;
  }
  
  .player-controls .loop-control {
    left: 12px;
  }
  
  .mode-btn {
    min-width: 80px;
  }
}

/* 中等屏幕（375px-430px）适配 */
@media (min-width: 376px) and (max-width: 430px) {
  .lyrics-container {
    padding: 0 24px;
    padding-bottom: 260px;
  }
  
  .bottom-controls-bg {
    padding: 0 24px;
  }
  
  .player-controls .loop-control {
    left: 24px;
  }
}

/* 大屏适配（>430px）*/
@media (min-width: 431px) {
  .lyrics-container {
    padding: 0 40px;
    padding-bottom: 260px;
  }
  
  .bottom-controls-bg {
    padding: 0 40px;
  }
  
  .player-controls .loop-control {
    left: 40px;
  }
}

/* 收起按钮 */
.collapse-btn {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(calc(-50% - 10px));
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.collapse-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(calc(-50% - 10px)) scale(1.05);
}

.collapse-btn .el-icon {
  font-size: 16px;
  color: rgba(255, 255, 255, 0.8);
  transition: all 0.3s ease;
}

.collapse-btn .rotate-180 {
  transform: rotate(180deg);
}

/* 键盘收起状态 */
.bottom-controls-bg.collapsed ~ .lyrics-container {
  padding-bottom: 140px;
}

/* 播放标志动画样式 */
.playing-indicator {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: flex-end;
  height: 14px;
  gap: 1px;
  z-index: 10;
}

.bar {
  width: 3px;
  background: linear-gradient(135deg, #8B5CF6 0%, #5B21B6 100%);
  border-radius: 1.5px;
  animation-duration: 1.2s;
  animation-iteration-count: infinite;
  animation-timing-function: ease-in-out;
}

.bar1 {
  height: 7px;
  animation-name: bar-anim-1;
}

.bar2 {
  height: 10px;
  animation-name: bar-anim-2;
}

.bar3 {
  height: 7px;
  animation-name: bar-anim-3;
}

@keyframes bar-anim-1 {
  0%, 100% { height: 7px; }
  50% { height: 14px; }
}

@keyframes bar-anim-2 {
  0%, 100% { height: 10px; }
  50% { height: 5px; }
}

@keyframes bar-anim-3 {
  0%, 100% { height: 7px; }
  50% { height: 12px; }
}

/* 设置按钮 */
.settings-btn {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 101;
}

.settings-btn:hover {
  opacity: 0.8;
}

.settings-btn .el-icon {
  font-size: 22px;
  color: white;
}

/* 设置面板样式 */
.settings-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
}

.settings-panel {
  position: fixed;
  top: 72px;
  right: 16px;
  width: 240px;
  background: rgba(26, 23, 50, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  z-index: 201;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.settings-header {
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.settings-header span {
  font-weight: 600;
  font-size: 16px;
  color: white;
}

.close-settings {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.1);
  transition: all 0.2s ease;
}

.close-settings:hover {
  background: rgba(255, 255, 255, 0.2);
}

.close-settings .el-icon {
  font-size: 14px;
  color: white;
}

.settings-content {
  padding: 16px;
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.setting-item:last-child {
  margin-bottom: 0;
}

.setting-label {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.9);
}

/* 设置开关样式 */
.setting-switch {
  width: 40px;
  height: 20px;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
}

.setting-switch:hover {
  background: rgba(255, 255, 255, 0.2);
}

.setting-switch.active {
  background: linear-gradient(135deg, #8B5CF6 0%, #5B21B6 100%);
  border-color: rgba(139, 92, 246, 0.5);
}

.setting-switch-slider {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 2px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: all 0.3s ease;
}

.setting-switch.active .setting-switch-slider {
  left: calc(100% - 18px);
}

/* 使用教程按钮 */
.tutorial-btn {
  position: fixed;
  bottom: 280px;
  right: 20px;
  padding: 0 16px;
  height: 40px;
  border-radius: 20px;
  background: linear-gradient(135deg, #8B5CF6 0%, #5B21B6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.5);
  cursor: pointer;
  z-index: 101;
  transition: all 0.3s ease;
}

.tutorial-btn:hover {
  transform: scale(1.05);
}

.tutorial-text {
  color: white;
  font-size: 14px;
  font-weight: 600;
}

/* 底部控制栏收起时的按钮位置调整 */
.bottom-controls-bg.collapsed ~ .tutorial-btn {
  bottom: 180px;
}

/* 小屏幕适配 */
@media (max-width: 375px) {
  .tutorial-btn {
    right: 15px;
    padding: 0 14px;
    height: 36px;
  }
  
  .tutorial-text {
    font-size: 13px;
  }
}

/* 超小屏（320px）适配 */
@media (max-width: 320px) {
  .tutorial-btn {
    right: 10px;
    padding: 0 12px;
    height: 32px;
  }
  
  .tutorial-text {
    font-size: 12px;
  }
}

/* 教程弹窗背景 */
.tutorial-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  z-index: 200;
}

/* 教程弹窗 */
.tutorial-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 85%;
  max-width: 320px;
  background: rgba(61, 56, 90, 0.98);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  z-index: 201;
  border: 1px solid rgba(139, 92, 246, 0.3);
  overflow: hidden;
}

.tutorial-header {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.tutorial-header h3 {
  margin: 0;
  color: white;
  font-size: 18px;
  font-weight: 600;
}

.close-tutorial {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
}

.close-tutorial:hover {
  background: rgba(255, 255, 255, 0.2);
}

.tutorial-content {
  padding: 20px;
}

.tutorial-step {
  display: flex;
  margin-bottom: 20px;
  align-items: center;
}

.tutorial-step:last-child {
  margin-bottom: 0;
}

.step-number {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #8B5CF6 0%, #5B21B6 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  margin-right: 12px;
  flex-shrink: 0;
}

.step-text {
  color: white;
  font-size: 15px;
  line-height: 1.4;
}

/* 超小屏下的教程弹窗适配 */
@media (max-width: 320px) {
  .tutorial-modal {
    width: 90%;
  }
  
  .step-text {
    font-size: 14px;
  }
}
</style> 